package com.fmy.security.service.defult;

import com.fmy.security.commons.tools.RequestTool;
import com.fmy.security.commons.unusual.TokenException;
import com.fmy.security.service.TokenExceptionHander;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName TokenExceptionHanderDefult
 * @Description TODO
 * @createTime 2019/9/6 15:14
 */
public class TokenExceptionHanderDefult implements TokenExceptionHander {
    @Override
    public void hander(HttpServletRequest request, HttpServletResponse response, TokenException e) throws IOException {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", e.getiEnum().getCode());
        result.put("errMsg", e.getMessage());
        RequestTool.responseWriter(response, HttpStatus.UNAUTHORIZED, result);
    }
}
